package com.theme.passport.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.SysUserEntity;
import com.theme.passport.entity.theme.ThemeEntity;
import com.theme.passport.service.SysUserService;
import com.theme.passport.service.theme.ThemeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("app/designer")
@Api("设计师信息相关接口")
public class DesignersController {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private ThemeService themeService;

    /**
     * @title: 设计师信息 <tb>
     * @params: 设计师id  <tb
     * @date: 2020/11/24 17:11<tb>
     */
    @GetMapping("/info")
    @ApiOperation("查询设计师详情信息接口")
    public R info(@RequestParam("designerId") Long designerId){
        SysUserEntity designer = sysUserService.getById(designerId);
        if (designer == null){
            return R.error("设计师不存在!!!");
        }
        QueryWrapper<ThemeEntity> orderWrapper = new QueryWrapper<>();
        orderWrapper.and(wrapper -> wrapper.eq("user_id", designerId));
        List<ThemeEntity> list = themeService.list(orderWrapper);
        designer.setThemeList(list);
        designer.setUsername(null);
        designer.setSalt(null);
        designer.setPassword(null);
        return R.ok().put("designer", designer);
    }

}
